package com.gadgets.framework.fm03.service.impl;

import com.gadgets.framework.common.constant.GadgetsExceptionConstant;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsException;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.PaginationUtil;
import com.gadgets.framework.fm03.dto.BusiNodeQueryDTO;
import com.gadgets.framework.fm03.pojo.BusiNodeInfo;
import com.gadgets.framework.fm03.repository.IBusiNodeInfoRepository;
import com.gadgets.framework.fm03.service.IBusiNodeManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiujunqing
 * @version V1.1.0
 * @data 2021-10-14
 * @moduel com.gadgets.framework.fm03.service.impl
 */
@Transactional(transactionManager = "gadgetsDbTransactionManage", rollbackFor = Throwable.class)
@Service
public class BusiNodeManagerServiceImpl implements IBusiNodeManagerService {

    @Autowired
    private IBusiNodeInfoRepository repository;

    /**
     * 新增流程节点信息
     * @param busiNodeInfo          节点信息
     * @throws GadgetsException     异常信息
     */
    @Override
    @Transactional(transactionManager = "gadgetsDbTransactionManage", rollbackFor = Throwable.class)
    public void addBusiNodeInfo(BusiNodeInfo busiNodeInfo) throws GadgetsException {
        int i = repository.insertNodeInfo(busiNodeInfo);
        if(i!=1){
            throw new GadgetsServiceException(GadgetsExceptionConstant.DATA_OPER_NUM_ERROR,1,i);
        }
    }

    /**
     * 条件查询节点信息
     *
     * @param queryDTO   查询条件
     * @param pagination 分页条件
     * @return 查询结果
     * @throws GadgetsException 异常信息
     */
    @Override
    @Transactional(transactionManager = "gadgetsDbTransactionManage", rollbackFor = Throwable.class, propagation = Propagation.SUPPORTS)
    public List<BusiNodeInfo> selectBusiNodeByCondition(BusiNodeQueryDTO queryDTO, Pagination pagination) throws GadgetsException {
        PaginationUtil.bulidPaginationInfo(pagination);
        List<BusiNodeInfo> queryList = repository.selectBusiNodeInfoByCondition(queryDTO);
        PaginationUtil.getPaginationResultInfo(queryList, pagination);
        return queryList;
    }
}
